<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>{include_php}</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="language.builtin.functions.html" title="Chapter 7. Built-in Functions">
<link rel="prev" href="language.function.include.html" title="{include}">
<link rel="next" href="language.function.insert.html" title="{insert}">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">{include_php}</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="language.function.include.html">Prev</a> </td>
<th width="60%" align="center">Chapter 7. Built-in Functions</th>
<td width="20%" align="right"> <a accesskey="n" href="language.function.insert.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="{include_php}">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="language.function.include.php"></a>{include_php}</h2></div></div></div>
<div class="note" title="IMPORTANT NOTICE" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">IMPORTANT NOTICE</h3>
<p>
    <code class="varname">{include_php}</code> is deprecated from Smarty, use registered plugins to properly insulate presentation from the application code.
    As of Smarty 3.1 the <code class="varname">{include_php}</code> tags are only available from <a class="link" href="bc.html" title="Chapter 19. SmartyBC - Backwards Compatibility Wrapper">SmartyBC</a>.
   </p>
</div>
<div class="informaltable"><table border="1">
<colgroup>
<col align="center">
<col align="center">
<col align="center">
<col align="center">
<col>
</colgroup>
<thead><tr>
<th align="center">Attribute Name</th>
<th align="center">Type</th>
<th align="center">Required</th>
<th align="center">Default</th>
<th>Description</th>
</tr></thead>
<tbody>
<tr>
<td align="center">file</td>
<td align="center">string</td>
<td align="center">Yes</td>
<td align="center"><span class="emphasis"><em>n/a</em></span></td>
<td>The name of the php file to include as absolute path</td>
</tr>
<tr>
<td align="center">once</td>
<td align="center">boolean</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em><code class="constant">TRUE</code></em></span></td>
<td>whether or not to include the php file more than
      once if included multiple times</td>
</tr>
<tr>
<td align="center">assign</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>n/a</em></span></td>
<td>The name of the variable that the output of
      include_php will be assigned to</td>
</tr>
</tbody>
</table></div>
<p><span class="bold"><strong>Option Flags:</strong></span></p>
<div class="informaltable"><table border="1">
<colgroup>
<col align="center">
<col>
</colgroup>
<thead><tr>
<th align="center">Name</th>
<th>Description</th>
</tr></thead>
<tbody><tr>
<td align="center">nocache</td>
<td>Disables caching of inluded PHP script</td>
</tr></tbody>
</table></div>
<p>
  <code class="varname">{include_php}</code> tags are used to include a php script in your template.
  The path of the attribute <em class="parameter"><code>file</code></em> can be
   either absolute, or relative to
   <a class="link" href="variable.trusted.dir.html" title="$trusted_dir"><em class="parameter"><code>$trusted_dir</code></em></a>. If security is enabled, then the 
   script must be located in the <em class="parameter"><code>$trusted_dir</code></em> path of the securty policy.
   See the <a class="link" href="advanced.features.html#advanced.features.security" title="Security">Security</a> section for details.
 </p>
<p>
  By default, php files are only included once even if called
  multiple times in the template. You can specify that it should be
  included every time with the <em class="parameter"><code>once</code></em> attribute.
  Setting once to <code class="constant">FALSE</code> will include the php script each time it is
  included in the template.
 </p>
<p>
  You can optionally pass the <em class="parameter"><code>assign</code></em> attribute,
  which will specify a template variable name that the output of
  <code class="varname">{include_php}</code> will be assigned to instead of
  displayed.
 </p>
<p>
  The smarty object is available as <em class="parameter"><code>$_smarty_tpl-&gt;smarty</code></em> within
  the PHP script that you include.
 </p>
<div class="example">
<a name="id376316"></a><p class="title"><b>Example 7.55. function {include_php}</b></p>
<div class="example-contents">
<p>The <code class="filename">load_nav.php</code> file:</p>
<pre class="programlisting">

&lt;?php

// load in variables from a mysql db and assign them to the template
require_once('database.class.php');
$db = new Db();
$db-&gt;query('select url, name from navigation order by name');
$this-&gt;assign('navigation', $db-&gt;getRows());

?&gt;

  </pre>
<p>
   where the template is:
  </p>
<pre class="programlisting">

{* absolute path, or relative to $trusted_dir *}
{include_php file='/path/to/load_nav.php'}
{include_php '/path/to/load_nav.php'}             {* short-hand *}

{foreach item='nav' from=$navigation}
  &lt;a href="{$nav.url}"&gt;{$nav.name}&lt;/a&gt;&lt;br /&gt;
{/foreach}

  </pre>
</div>
</div>
<br class="example-break"><p>
  See also <a class="link" href="language.function.include.html" title="{include}"><code class="varname">{include}</code></a>,
<a class="link" href="variable.trusted.dir.html" title="$trusted_dir"><em class="parameter"><code>$trusted_dir</code></em></a>,
  <a class="link" href="language.function.php.html" title="{php}"><code class="varname">{php}</code></a>, <a class="link" href="language.function.capture.html" title="{capture}"><code class="varname">{capture}</code></a>, <a class="link" href="resources.html" title="Chapter 16. Resources">template resources</a> and <a class="link" href="tips.componentized.templates.html" title="Componentized Templates">componentized templates</a> </p>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="language.function.include.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="language.builtin.functions.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="language.function.insert.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">{include} </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> {insert}</td>
</tr>
</table>
</div>
</body>
</html>
